#!/usr/bin/make -f
# debian/rules for camlimages package
# Copyright (C) 2006-2008 Sylvain Le Gall <gildor@debian.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/dpatch.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/class/ocaml.mk

PACKAGE := libcamlimages-ocaml
DESTDIR := $(CURDIR)/debian/$(PACKAGE)

PACKAGE_DEV := libcamlimages-ocaml-dev
DESTDIR_DEV := $(CURDIR)/debian/$(PACKAGE_DEV)

PACKAGE_DOC := libcamlimages-ocaml-doc
DESTDIR_DOC := $(CURDIR)/debian/$(PACKAGE_DOC)

LABLGTK2_DIR := $(shell ocamlfind query lablgtk2)

DEB_CONFIGURE_EXTRA_FLAGS := --with-lablgtk2="$(LABLGTK2_DIR)" \
                             --without-lablgtk

DEB_MAKE_CLEAN_TARGET    := veryclean

DEB_MAKE_BUILD_TARGET    := byt
ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
DEB_MAKE_BUILD_TARGET    += opt 
endif

DEB_MAKE_INSTALL_TARGET  := install.byt
ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
DEB_MAKE_INSTALL_TARGET  += install.opt
endif
DEB_MAKE_INSTALL_TARGET  += DESTDIR="$(DESTDIR_DEV)"

DEB_INSTALL_EXAMPLES_libcamlimages-ocaml-doc := -X Makefile -X .depend
DEB_DH_INSTALL_ARGS                          := -X LICENSE -X README -X INSTALL -X Makefile

OCAML_OCAMLDOC_PACKAGES := $(PACKAGE_DEV)
OCAML_OCAMLDOC_FLAGS := -I $(DESTDIR_DEV)/$(OCAML_STDLIB_DIR)/camlimages/ \
  			$(shell ocamlfind query -i-format lablgtk2)

clean::
	-test -L '$(CURDIR)/html' && $(RM) '$(CURDIR)/html'
	-test -L '$(CURDIR)/doc/index.html' && $(RM) '$(CURDIR)/doc/index.html'
	-$(RM) '$(CURDIR)/Makefile.config'
	-$(RM) -r '$(CURDIR)/freetype'
	-$(RM) '$(CURDIR)/debian/META.camlimages'
	-$(RM) '$(CURDIR)/debian/libcamlimages-ocaml.dirs'
	-$(RM) '$(CURDIR)/debian/libcamlimages-ocaml-dev.dirs'
	-$(RM) '$(CURDIR)/debian/libcamlimages-ocaml-dev.install'

install/libcamlimages-ocaml-dev::
	VERSION=$(DEB_NOEPOCH_VERSION); \
	VERSION=$${VERSION%%-*}; \
	sed -i "s/@VERSION@/$$VERSION/g" debian/META.camlimages
	mv $(DESTDIR_DEV)/$(OCAML_STDLIB_DIR)/camlimages/*.so \
	 $(DESTDIR)/$(OCAML_DLL_DIR)/
	chrpath -d $(DESTDIR)/$(OCAML_DLL_DIR)/*.so


